<?php

namespace App\Http\Controllers;

use App\Library\HandleFile;
use App\Models\Goods;
use Exception;
use Illuminate\Http\Request;

/**
 * 积分实物商品相关
 */
class GoodsController extends Controller
{
    /**
     * 积分实物商品详情
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function goods_info(Request $request)
    {
        try {
            $status   = 0;
            $data     = [];
            $goods_id = $request->get('goods_id');
            if (empty($goods_id)) {
                throw new Exception('缺少参数');
            }
            $goods = Goods::where(['goods_id' => $goods_id])->first();
            //处理数据
            $data['kill_id']   = $goods->integral_kill->kill_id;
            $data['goods_id']  = $goods->goods_id;
            $data['name']      = $goods->name;
            $data['photo']     = $goods->photo;
            $data['introduce'] = $goods->introduce;
            $data['price']     = sprintf('%.2f', $goods->price);
            $data['integral']  = $goods->integral_kill->integral;
            if ($goods->details_type == 2) {
                $data['details'] = HandleFile::handleFilePath($goods->details, $goods->details_oss);
            } else {
                $data['details'] = $goods->details;
            }

            $status = 1;
            $msg    = '查询成功';
        } catch (Exception $e) {
            $msg = $e->getMessage();
        }

        return response()->json(['status' => $status, 'msg' => $msg, 'data' => $data]);
    }
}
